package com.luyuan.web.controller.gallery;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.luyuan.common.core.domain.AjaxResult;
import com.luyuan.gallery.domain.ExhiCommentLike;
import com.luyuan.gallery.service.IExhiCommentLikeService;

/**
 * 评论点赞Controller
 * 
 * @author luyuan
 * @date 2025-11-08
 */
@RestController
@RequestMapping("/gallery/comment/like")
public class ExhiCommentLikeController {

    @Autowired
    private IExhiCommentLikeService exhiCommentLikeService;

    /**
     * 查询评论点赞列表
     */
    @GetMapping("/list")
    public AjaxResult list(ExhiCommentLike exhiCommentLike) {
        List<ExhiCommentLike> list = exhiCommentLikeService.selectExhiCommentLikeList(exhiCommentLike);
        return AjaxResult.success(list);
    }

    /**
     * 获取评论点赞详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(exhiCommentLikeService.selectExhiCommentLikeById(id));
    }

    /**
     * 新增评论点赞
     */
    @PostMapping
    public AjaxResult add(@RequestBody ExhiCommentLike exhiCommentLike) {
        int rows = exhiCommentLikeService.insertExhiCommentLike(exhiCommentLike);
        return rows > 0 ? AjaxResult.success() : AjaxResult.error();
    }

    /**
     * 修改评论点赞
     */
    @PutMapping
    public AjaxResult edit(@RequestBody ExhiCommentLike exhiCommentLike) {
        int rows = exhiCommentLikeService.updateExhiCommentLike(exhiCommentLike);
        return rows > 0 ? AjaxResult.success() : AjaxResult.error();
    }

    /**
     * 删除评论点赞
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return AjaxResult.success(exhiCommentLikeService.deleteExhiCommentLikeByIds(ids));
    }

    /**
     * 点赞或取消点赞评论
     */
    @PutMapping("/toggle/{commentId}")
    public AjaxResult likeOrUnlike(@PathVariable Long commentId, Long userId) {
        int rows = exhiCommentLikeService.likeOrUnlikeComment(commentId, userId);
        return rows > 0 ? AjaxResult.success() : AjaxResult.error();
    }
}